package com.ohc.leetcode.链表;

import java.util.HashSet;

/**
 * 2022年6月20日09:55:26
 * https://leetcode.cn/problems/intersection-of-two-linked-lists-lcci/
 */
public class 面试题0207链表相交 {
    public static class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
            next = null;
        }
    }

    public static ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        HashSet<ListNode> set = new HashSet<>();
        while (headA != null) {
            set.add(headA);
        }
        while (headB != null) {
            if (set.contains(headB)) {
                return headB;
            }
        }
        return null;
    }

    public static void main(String[] args) {
//        getIntersectionNode();
    }
}
